home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 6.5 KB | 247 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPalete.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPALETE_H
- #include "FWPalete.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__QDOFFSCREEN__)
- #include <QDOffscreen.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphix_Palette
- #endif
-
- //========================================================================================
- // Palette functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CreatePalette
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_Palette FW_CreatePalette(
- short nSize,
- const FW_CColor* colors,
- short nColorCount)
- {
- #ifdef FW_BUILD_WIN
- LOGPALETTE* pLogPal = (LOGPALETTE*) new char[sizeof(LOGPALETTE) + nColorCount * sizeof(PALETTEENTRY)];
- pLogPal->palVersion = 0x300;
- pLogPal->palNumEntries = nColorCount;
-
- for (short i = 0; i < nColorCount; ++ i)
- {
- RGBQUAD rgb = colors[i];
-
- pLogPal->palPalEntry[i].peBlue = rgb.rgbBlue;
- pLogPal->palPalEntry[i].peGreen = rgb.rgbGreen;
- pLogPal->palPalEntry[i].peRed = rgb.rgbRed;
- pLogPal->palPalEntry[i].peFlags = 0;
- }
-
- HPALETTE hPal = ::CreatePalette(pLogPal);
-
- delete[] (char*) pLogPal;
-
- return hPal;
- #endif
- #ifdef FW_BUILD_MAC
- Size colorTableSize = sizeof(ColorTable) + sizeof(ColorSpec) * (nColorCount - 1);
- FW_CAcquireTemporarySystemHandle colorTableMemory(colorTableSize);
- CTabPtr colorTablePtr = (CTabPtr) colorTableMemory.GetPointer();
-
- colorTablePtr->ctSeed = 0;
- colorTablePtr->ctFlags = 0;
- colorTablePtr->ctSize = nColorCount - 1;
-
- for (short i = 0; i < nColorCount; ++ i)
- {
- colorTablePtr->ctTable[i].value = i;
- colorTablePtr->ctTable[i].rgb = colors[i];
- }
-
- colorTableMemory.Orphan();
- CTabHandle hCTab = (CTabHandle) colorTableMemory.GetPlatformHandle();
-
- ::CTabChanged(hCTab);
- return hCTab;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_GetPaletteSize
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR short FW_GetPaletteSize(FW_Palette palette)
- {
- FW_ASSERT(palette != NULL);
-
- #ifdef FW_BUILD_WIN
- WORD wCount;
- ::GetObject(palette, sizeof(WORD), &wCount);
- return wCount;
- #endif
- #ifdef FW_BUILD_MAC
- return (*palette)->ctSize + 1;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SetPaletteEntries
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR void FW_SetPaletteEntries(
- FW_Palette palette,
- const FW_CColor* colors,
- short nStartIndex,
- short nColorCount)
- {
- FW_ASSERT(palette != NULL);
- FW_ASSERT(nStartIndex + nColorCount <= FW_GetPaletteSize(palette));
-
- #ifdef FW_BUILD_WIN
- PALETTEENTRY* pPalEntries = new PALETTEENTRY[nColorCount];
-
- for (short i = 0; i < nColorCount; ++i, ++colors)
- {
- RGBQUAD rgb = *colors;
-
- pPalEntries[i].peBlue = rgb.rgbBlue;
- pPalEntries[i].peGreen = rgb.rgbGreen;
- pPalEntries[i].peRed = rgb.rgbRed;
- pPalEntries[i].peFlags = 0;
- }
-
- ::SetPaletteEntries(palette, nStartIndex, nColorCount, pPalEntries);
-
- delete[] pPalEntries;
- #endif
- #ifdef FW_BUILD_MAC
- FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)palette);
- CTabPtr colorTablePtr = (CTabPtr) lock.GetPointer();
-
- for (short i = nStartIndex; i < nStartIndex + nColorCount; ++ i, ++ colors)
- {
- colorTablePtr->ctTable[i].value = i;
- colorTablePtr->ctTable[i].rgb = *colors;
- }
-
- ::CTabChanged(palette);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_GetPaletteEntries
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR void FW_GetPaletteEntries(
- FW_Palette palette,
- FW_CColor* colors,
- short nStartIndex,
- short nColorCount)
- {
- FW_ASSERT(palette != NULL);
- FW_ASSERT(nStartIndex + nColorCount <= FW_GetPaletteSize(palette));
-
- #ifdef FW_BUILD_WIN
- PALETTEENTRY* pPalEntries = new PALETTEENTRY[nColorCount];
-
- ::GetPaletteEntries(palette, nStartIndex, nColorCount, pPalEntries);
-
- for (short i = 0; i < nColorCount; ++i, ++colors)
- {
- RGBQUAD rgb = *colors;
-
- rgb.rgbBlue = pPalEntries[i].peBlue;
- rgb.rgbGreen = pPalEntries[i].peGreen;
- rgb.rgbRed = pPalEntries[i].peRed;
-
- *colors = rgb;
- }
-
- delete[] pPalEntries;
- #endif
- #ifdef FW_BUILD_MAC
- FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)palette);
- CTabPtr colorTablePtr = (CTabPtr) lock.GetPointer();
-
- for (short i = nStartIndex; i < nStartIndex + nColorCount; ++ i, ++ colors)
- {
- *colors = colorTablePtr->ctTable[i].rgb;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CopyPalette
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_Palette FW_CopyPalette(FW_Palette palette)
- {
- FW_ASSERT(palette != NULL);
-
- #ifdef FW_BUILD_WIN
- WORD wCount;
- ::GetObject(palette, sizeof(WORD), &wCount);
-
- LOGPALETTE* pLogPal = (LOGPALETTE*) new char[sizeof(LOGPALETTE) + wCount * sizeof(PALETTEENTRY)];
-
- pLogPal->palVersion = 0x300;
- pLogPal->palNumEntries = wCount;
-
- ::GetPaletteEntries(palette, 0, wCount, pLogPal->palPalEntry);
- HPALETTE hPalCopy = ::CreatePalette(pLogPal);
-
- delete[] (char*) pLogPal;
-
- return hPalCopy;
- #endif
- #ifdef FW_BUILD_MAC
- FW_Palette palCopy = (FW_Palette)
- FW_CMemoryManager::CopySystemHandle((FW_PlatformHandle)palette);
- (*palCopy)->ctSeed = 0;
- ::CTabChanged(palCopy);
- return palCopy;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_DestroyPalete
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR void FW_DestroyPalete(FW_Palette palette)
- {
- #ifdef FW_BUILD_WIN
- ::DeleteObject(palette);
- #endif
- #ifdef FW_BUILD_MAC
- ::DisposeCTable(palette);
- #endif
- }
-